package com.weitu.worklicense.service.impl;

import com.weitu.accessory.util.AccessoryUtil;
import com.weitu.worklicense.entity.ElectricityLicense;
import com.weitu.worklicense.mapper.ElectricityLicenseMapper;
import com.weitu.worklicense.service.ElectricityLicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/6/9.
 */
@Service
public class ElectricityLicenseServiceImpl implements ElectricityLicenseService {

    private final ElectricityLicenseMapper electricityLicenseMapper;

    @Autowired
    public ElectricityLicenseServiceImpl(ElectricityLicenseMapper electricityLicenseMapper){
        this.electricityLicenseMapper=electricityLicenseMapper;
    }

    @Override
    public int queryCount(Map<String, Object> map) {
        return this.electricityLicenseMapper.queryCount(map);
    }

    @Override
    public List<ElectricityLicense> queryList(Map<String, Object> map) {
        return this.electricityLicenseMapper.queryList(map);
    }

    @Override
    @Transactional
    public boolean insertElectricityLicense(ElectricityLicense electricityLicense) {
        boolean flag=false;
        int count=this.electricityLicenseMapper.insertElectricityLicense(electricityLicense);
        if(count==1)
            flag=true;
        boolean flag2= AccessoryUtil.saveAccerssoryInfo(electricityLicense.getId());
        return flag&&flag2;
    }

    @Override
    public ElectricityLicense queryById(String id) {
        return this.electricityLicenseMapper.queryById(id);
    }

    @Override
    @Transactional
    public boolean updateElectricityLicense(ElectricityLicense electricityLicense) {
        boolean flag=false;
        int count=this.electricityLicenseMapper.updateElectricityLicense(electricityLicense);
        if(count==1)
            flag=true;
        boolean flag2= AccessoryUtil.saveAccerssoryInfo(electricityLicense.getId());
        return flag&&flag2;
    }

    @Override
    public int deleteElectricity(String id) {
        return this.electricityLicenseMapper.deleteElectricity(id);
    }

    @Override
    public int execute(String id) {
        return this.electricityLicenseMapper.execute(id);
    }
}
